home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 7.0 KB | 274 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWGrUtil.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWGRUTIL_H
- #include "FWGrUtil.h"
- #endif
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWPOINT_H
- #include "FWPoint.h"
- #endif
-
- #ifndef FWFXMATH_H
- #include "FWFxMath.h"
- #endif
-
- #ifndef FWGCONST_H
- #include "FWGConst.h"
- #endif
-
- #ifndef SLREGION_H
- #include "SLRegion.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWERRORS_H
- #include "FWErrors.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- // ----- C Includes -----
-
- #if defined(FW_BUILD_MAC) & !defined(__FP__)
- #include <FP.h>
- #endif
-
- #if defined(FW_BUILD_WIN) & !defined(__MATH_H)
- #include <Math.h>
- #endif
-
- #ifdef FW_DEBUG
- #include <stdio.h> // for sprintf()
- #endif
-
- // ------ Platform includes ------
-
- #if defined(FW_BUILD_MAC) & !defined(__QDOFFSCREEN__)
- #include <QDOffscreen.h>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWGraphx_GrUtil
- #endif
-
- //========================================================================================
- // Global Methods
- //========================================================================================
-
- //-------------------------------------------------------------------------
- // FW_CreateLineODShape
- //-------------------------------------------------------------------------
-
- ODShape* FW_CreateLineODShape(Environment *ev, const FW_CPoint& from, const FW_CPoint& to, FW_Fixed penSize)
- {
- FW_CPoint lineThickness(penSize, penSize);
-
- ODShape* shape = ::FW_NewODShape(ev);
- ODRgnHandle shapeRgn = ::FW_CreateLineRegion(from, to, lineThickness);
- if(shapeRgn == nil)
- FW_SetEvError(ev, FW_xRegionOverflow);
- else
- ::FW_SetShapeRegion(ev, shape, shapeRgn);
- return shape;
- }
-
- ODPolygon* FW_CreateODPolygon(Environment *ev, long inPointCount, const FW_SPoint* inPoints)
- {
- FW_UNUSED(ev);
-
- ODPolygon *poly = NULL;
- ODPoint *points = new ODPoint[inPointCount];
-
- if(points != NULL)
- {
- poly = new ODPolygon;
-
- if(poly != NULL)
- {
- for(long ixPoint = 0; ixPoint < inPointCount; ixPoint++)
- {
- points[ixPoint].x = inPoints[ixPoint].x.fRep;
- points[ixPoint].y = inPoints[ixPoint].y.fRep;
- }
-
- poly->SetVertices(inPointCount, points);
- }
-
- delete [] points;
- }
-
- return poly;
- }
-
- ODShape* FW_CreatePolygonODShape(Environment *ev, long inPointCount, const FW_SPoint* inPoints)
- {
- ODShape* shape = NULL;
-
- ODPolygon *poly = FW_CreateODPolygon(ev, inPointCount, inPoints);
-
- if(poly == NULL)
- FW_SetEvError(ev, FW_xMemoryExhausted);
- else
- {
- shape = ::FW_NewODShape(ev);
-
- if(shape != NULL)
- shape = shape->SetPolygon(ev, poly);
- else
- delete poly;
- }
-
- return shape;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CreateOvalODShape
- //----------------------------------------------------------------------------------------
-
- ODShape* FW_CreateOvalODShape(Environment *ev, const FW_CRect& rect)
- {
- ODShape* shape = ::FW_NewODShape(ev);
- ODRgnHandle shapeRgn = ::FW_CreateOvalRegion(rect);
- if(shapeRgn == nil)
- FW_SetEvError(ev, FW_xRegionOverflow);
- else
- ::FW_SetShapeRegion(ev, shape, shapeRgn);
- return shape;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CreateArcODShape
- //----------------------------------------------------------------------------------------
-
- ODShape* FW_CreateArcODShape(Environment *ev, const FW_CRect& rect, short startAngle, short arcAngle)
- {
- ODShape* shape = ::FW_NewODShape(ev);
- ODRgnHandle shapeRgn = ::FW_CreateArcRegion(rect, startAngle, arcAngle);
- if(shapeRgn == nil)
- FW_SetEvError(ev, FW_xRegionOverflow);
- else
- ::FW_SetShapeRegion(ev, shape, shapeRgn);
- return shape;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CreateRoundRectODShape
- //----------------------------------------------------------------------------------------
-
- ODShape* FW_CreateRoundRectODShape(Environment *ev, const FW_CRect& rect, const FW_CPoint& ovalSize)
- {
- ODShape* shape = ::FW_NewODShape(ev);
- ODRgnHandle shapeRgn = ::FW_CreateRoundRectRegion(rect, ovalSize);
- if(shapeRgn == nil)
- FW_SetEvError(ev, FW_xRegionOverflow);
- else
- ::FW_SetShapeRegion(ev, shape, shapeRgn);
- return shape;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_OutlineODShape
- //----------------------------------------------------------------------------------------
-
- void FW_OutlineODShape(Environment *ev, ODShape* odShapeToOutline, FW_Fixed outlineSize)
- {
- ODShape* odTempShape = ::FW_NewODShape(ev, odShapeToOutline);
-
- if (outlineSize <= FW_kFixed0)
- outlineSize = FW_kFixedPos1;
-
- odTempShape->Outset(ev, - FW_FixedToODFixed(outlineSize));
-
- odShapeToOutline->Subtract(ev, odTempShape);
- odTempShape->Release(ev);
- }
-
- #ifdef FW_BUILD_MAC
- //========================================================================================
- // class FW_CMacTempPort
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CMacTempPort)
-
- //----------------------------------------------------------------------------------------
- // FW_CMacTempPort::PrivSaveAndSet
- //----------------------------------------------------------------------------------------
-
- void FW_CMacTempPort::PrivSaveAndSet(CGrafPtr tempPort, GDHandle tempDevice)
- {
- ::GetGWorld(&fMacPort, &fGDevice);
-
- if (tempPort != NULL)
- SetGWorld(tempPort, tempDevice);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMacTempPort::FW_CMacTempPort
- //----------------------------------------------------------------------------------------
-
- FW_CMacTempPort::FW_CMacTempPort(CGrafPtr tempPort /* = NULL */, GDHandle tempDevice /* = NULL */)
- {
- PrivSaveAndSet(tempPort, tempDevice);
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMacTempPort::FW_CMacTempPort
- //----------------------------------------------------------------------------------------
-
- FW_CMacTempPort::FW_CMacTempPort(GrafPtr tempPort, GDHandle tempDevice /* = NULL */)
- {
- PrivSaveAndSet((CGrafPtr) tempPort, tempDevice);
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMacTempPort::~FW_CMacTempPort
- //----------------------------------------------------------------------------------------
-
- FW_CMacTempPort::~FW_CMacTempPort()
- {
- FW_START_DESTRUCTOR
-
- ::SetGWorld(fMacPort, fGDevice);
- }
-
- #endif
-
-